{extend name="public/container"}
{block name='head_top'}
<script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/third-party/zeroclipboard/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="{__ADMIN_PATH}plug/ueditor/lang/zh-cn/zh-cn.js"></script>
{/block}
{block name="content"}
<div class="layui-fluid" style="background: #fff; padding-bottom: 20px;">
    <div class="layui-row layui-col-space15"  id="app">
        <form action="" class="layui-form">
            <div class="layui-col-md12">
                <div class="layui-card" v-cloak="">

                    <div class="layui-card-body" style="padding: 10px 80px;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">协议标题</label>
                            <div class="layui-input-block">
                                <input type="text" v-model="formData.title" autocomplete="off" placeholder="协议标题" class="layui-input" readonly="readonly" />
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">协议内容</label>
                            <div class="layui-input-block">
                                <textarea id="myEditor" style="width:100%;height: 500px">{{formData.content}}</textarea>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

            <div class="layui-col-md12" style="padding-right: 80px;">
                <div class="layui-form-item submit pull-right">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" type="button" @click="save">{$id ? '确认修改':'立即提交'}</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="{__ADMIN_PATH}js/layuiList.js"></script>
{/block}
{block name='script'}
<script>
    var data = <?=isset($data) ? $data : "{}"?>;
    require(['vue'],function(Vue) {
        new Vue({
            el: "#app",
            data: {
                formData:{
                    id:data.id || 0,
                    title:data.title || '协议条款',
                    content:data.content || '',
                },
                ue:null
            },
            methods:{
                save:function () {
                    var that=this;

                    that.formData.content = that.ue.getContent();

                    if(!that.formData.title) return layList.msg('协议标题不能为空');
                    if(!that.formData.content) return layList.msg('协议内容不能为空');

                    layList.loadFFF();
                    layList.basePost(layList.U({a:'save'}),that.formData,function (res) {
                        layList.loadClear();
                        layList.msg('操作成功' , function() {
                            window.location.reload();
                        });
                    },function (res) {
                        layList.msg(res.msg);
                        layList.loadClear();
                    });
                }
            },
            mounted:function () {
                var that=this;

                //实例化编辑器
                that.ue = UE.getEditor('myEditor');

                this.$nextTick(function () {
                    layList.form.render();
                });
            }
        })
    })

</script>
{/block}